﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace BlondeHeaven.Model.Migrations
{
    public partial class InitialCreate : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Uesrs",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Name = table.Column<string>(nullable: true),
                    IsRemo = table.Column<bool>(nullable: false),
                    DateTime = table.Column<DateTime>(nullable: false),
                    Age = table.Column<int>(nullable: false),
                    Sex = table.Column<bool>(nullable: false),
                    Phone = table.Column<string>(maxLength: 40, nullable: false),
                    Photo = table.Column<string>(maxLength: 5000, nullable: true),
                    Address = table.Column<string>(nullable: true),
                    PassWrod = table.Column<string>(maxLength: 50, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Uesrs", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Waiters",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Name = table.Column<string>(nullable: true),
                    IsRemo = table.Column<bool>(nullable: false),
                    DateTime = table.Column<DateTime>(nullable: false),
                    Photo = table.Column<string>(nullable: true),
                    Sex = table.Column<bool>(nullable: false),
                    Phone = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Waiters", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "ShopKeepers",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Name = table.Column<string>(nullable: true),
                    IsRemo = table.Column<bool>(nullable: false),
                    DateTime = table.Column<DateTime>(nullable: false),
                    Address = table.Column<string>(nullable: true),
                    Photo = table.Column<string>(nullable: true),
                    Phone = table.Column<string>(nullable: true),
                    Sales = table.Column<int>(nullable: false),
                    UserId = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ShopKeepers", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ShopKeepers_Uesrs_UserId",
                        column: x => x.UserId,
                        principalTable: "Uesrs",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "Comments",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Name = table.Column<string>(nullable: true),
                    IsRemo = table.Column<bool>(nullable: false),
                    DateTime = table.Column<DateTime>(nullable: false),
                    Content = table.Column<string>(maxLength: 3000, nullable: false),
                    ShopKeeperId = table.Column<int>(nullable: false),
                    UserId = table.Column<int>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Comments", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Comments_ShopKeepers_ShopKeeperId",
                        column: x => x.ShopKeeperId,
                        principalTable: "ShopKeepers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_Comments_Uesrs_UserId",
                        column: x => x.UserId,
                        principalTable: "Uesrs",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "Commoditys",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Name = table.Column<string>(nullable: true),
                    IsRemo = table.Column<bool>(nullable: false),
                    DateTime = table.Column<DateTime>(nullable: false),
                    CreateCommodity = table.Column<DateTime>(nullable: false),
                    Price = table.Column<double>(nullable: false),
                    Photo = table.Column<string>(nullable: true),
                    ShopKeeperId = table.Column<int>(nullable: false),
                    UserId = table.Column<int>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Commoditys", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Commoditys_ShopKeepers_ShopKeeperId",
                        column: x => x.ShopKeeperId,
                        principalTable: "ShopKeepers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_Commoditys_Uesrs_UserId",
                        column: x => x.UserId,
                        principalTable: "Uesrs",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "Orders",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Name = table.Column<string>(nullable: true),
                    IsRemo = table.Column<bool>(nullable: false),
                    DateTime = table.Column<DateTime>(nullable: false),
                    Price = table.Column<double>(nullable: false),
                    ShopKeeperId = table.Column<int>(nullable: false),
                    UserId = table.Column<int>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Orders", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Orders_ShopKeepers_ShopKeeperId",
                        column: x => x.ShopKeeperId,
                        principalTable: "ShopKeepers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_Orders_Uesrs_UserId",
                        column: x => x.UserId,
                        principalTable: "Uesrs",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "Rankings",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Name = table.Column<string>(nullable: true),
                    IsRemo = table.Column<bool>(nullable: false),
                    DateTime = table.Column<DateTime>(nullable: false),
                    ShopKeeperId = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Rankings", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Rankings_ShopKeepers_ShopKeeperId",
                        column: x => x.ShopKeeperId,
                        principalTable: "ShopKeepers",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_Comments_ShopKeeperId",
                table: "Comments",
                column: "ShopKeeperId");

            migrationBuilder.CreateIndex(
                name: "IX_Comments_UserId",
                table: "Comments",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_Commoditys_ShopKeeperId",
                table: "Commoditys",
                column: "ShopKeeperId");

            migrationBuilder.CreateIndex(
                name: "IX_Commoditys_UserId",
                table: "Commoditys",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_Orders_ShopKeeperId",
                table: "Orders",
                column: "ShopKeeperId");

            migrationBuilder.CreateIndex(
                name: "IX_Orders_UserId",
                table: "Orders",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_Rankings_ShopKeeperId",
                table: "Rankings",
                column: "ShopKeeperId");

            migrationBuilder.CreateIndex(
                name: "IX_ShopKeepers_UserId",
                table: "ShopKeepers",
                column: "UserId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "Comments");

            migrationBuilder.DropTable(
                name: "Commoditys");

            migrationBuilder.DropTable(
                name: "Orders");

            migrationBuilder.DropTable(
                name: "Rankings");

            migrationBuilder.DropTable(
                name: "Waiters");

            migrationBuilder.DropTable(
                name: "ShopKeepers");

            migrationBuilder.DropTable(
                name: "Uesrs");
        }
    }
}
